﻿Public Class masdrgtime
    Private TIMEID = Nothing
    Private DTCODE = Nothing
    Private DTNAME = Nothing
    Private QTY = Nothing
    Private STATUS = Nothing
    Private selectMasdrgtime = "SELECT `timeid` as 'รหัส', `dtcode` as 'รหัสระบุเวลา', `dtname` as 'วิธีการใช้ยา', `qty` as 'จำนวนครั้งที่ใช้ยา', `status` as 'สถานะการเปิดใช้งาน' FROM masdrgtime"
    'Private selectMasdrgacc = "SELECT DGTYID, DRGTYPE, convert(bit, [STATUS]) FROM MASDRGTYPE"

    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection

    Property TIMEID_ As Integer
        Get
            Return TIMEID
        End Get
        Set(value As Integer)
            TIMEID = value
        End Set
    End Property

    Property DTCODE_ As String
        Get
            Return DTCODE
        End Get
        Set(value As String)
            DTCODE = value
        End Set
    End Property

    Property DTNAME_ As String
        Get
            Return DTNAME
        End Get
        Set(value As String)
            DTNAME = value
        End Set
    End Property

    Property QTY_ As Integer
        Get
            Return QTY
        End Get
        Set(value As Integer)
            QTY = value
        End Set
    End Property

    Property STATUS_ As Boolean
        Get
            Return STATUS
        End Get
        Set(value As Boolean)
            If value = True Then
                STATUS = 1
            Else
                STATUS = 0
            End If
        End Set
    End Property

    Property selectMasdrgtime_ As String
        Get
            Return selectMasdrgtime
        End Get
        Set(value As String)

        End Set
    End Property

    Public Sub insertMasdrgtimeData()
        If TypeOf DTNAME Is String Then
            If connect.GetTable("SELECT timeid FROM masdrgtime WHERE dtcode = '" & DTCODE & "'").Rows.Count > 0 Then
                MsgBox("มีข้อมูลเวลาในการใข้ยานี้อยู่ในระบบแล้ว")
            Else
                Try
                    connect = CONDB.NewConnection()
                    'connectlocal = conlocal.NewConnection()
                    'Dim dischargeID As Integer

                    connect.ExecuteNonQuery("INSERT INTO masdrgtime (dtcode, dtname, qty, status) VALUES ('" & DTCODE & "', '" & DTNAME & "', '" & QTY & "', '" & STATUS & "')")
                    'dischargeID = connect.ExecuteScalar("INSERT INTO masdischarge (DISCHARGE, STATUS) VALUES ('" & masdischargeDescription & "', '" & masdischargeStatus & "'); SELECT LAST_INSERT_ID();")
                    'connectlocal.ExecuteNonQuery("INSERT INTO MASDISCHARGE (DISCHGID, DISCHARGE, STATUS) VALUES ('" & dischargeID & "', '" & masdischargeDescription & "', '" & masdischargeStatus & "')")
                    MsgBox("ท่านได้ทำการเพิ่มข้อมูลเวลาในการใข้ยาเรียบร้อยแล้ว")
                Catch ex As Exception
                    MsgBox(vbCrLf & ex.Message)
                End Try
                connect.Dispose()
                'connectlocal.Dispose()
            End If
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
        End If
    End Sub

    Public Sub editMasdrgtimeData()
        If TypeOf DTNAME Is String Then
            Try
                connect = CONDB.NewConnection()
                'connectlocal = conlocal.NewConnection()

                connect.ExecuteNonQuery("UPDATE masdrgtime SET dtcode = '" & DTCODE & "', dtname = '" & DTNAME & "', qty = '" & QTY & "', status = '" & STATUS & "' WHERE TIMEID = '" & TIMEID & "'")
                'connectlocal.ExecuteNonQuery("UPDATE MASDISCHARGE SET DISCHARGE = '" & masdischargeDescription & "', STATUS = '" & masdischargeStatus & "' WHERE DISCHGID = '" & masdischargeID & "'")
                MsgBox("ท่านได้ทำการแก้ไขข้อมูลเวลาการใช้ยาเรียบร้อยแล้ว")
            Catch ex As Exception
                MsgBox(vbCrLf & ex.Message)
            End Try
            connect.Dispose()
            'connectlocal.Dispose()
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
        End If
    End Sub
End Class
